package com.project.platformuser.user.controller;

import com.project.platformcommon.constants.Constants;
import com.project.platformcommon.resp.ApiResult;
import com.project.platformuser.user.entity.UserInfo;
import com.project.platformuser.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/register")
    public ApiResult userRegister(@RequestBody @Valid UserInfo user){
        ApiResult result = new ApiResult<>(Constants.RESP_STATUS_OK,"注册成功！");
        try {
            userService.registerUser(user);
        }catch (Exception e){
            result.setCode(500);
            result.setMessage("注册异常！");
            throw e;
        }
        return result;
    }

    @RequestMapping("/verNumber")
    public ApiResult verNumber(@RequestBody @Valid UserInfo user){
        ApiResult result = new ApiResult<>(Constants.RESP_STATUS_OK,"获取校验码成功！");
        try {
            userService.setUserActStatus(user);
        }catch (Exception e){

        }
        return result;
    }
}